import { IsString, MinLength, MaxLength, ValidateNested, IsArray, IsNumber } from "class-validator";
import { Type } from "class-transformer";
import { UserProfileDto } from "./user-profile.dto";

/**
 * 用户创建参数DTO
 */
export class CreateUserDto {
  @IsString({ message: "用户名必须是字符串" })
  @MinLength(2, { message: "用户名长度不能少于2个字符" })
  @MaxLength(20, { message: "用户名长度不能超过20个字符" })
  username: string;

  @IsString({ message: "密码必须是字符串" })
  @MinLength(6, { message: "密码长度不能少于6个字符" })
  password: string;

  @ValidateNested({ message: "用户个人信息格式不正确" })
  @Type(() => UserProfileDto)
  profile: UserProfileDto;

  @IsArray({ message: "分配角色必须是数组" })
  @IsNumber({}, { each: true, message: "角色ID必须是数字" })
  roles: Array<number>;
}
